package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author:何包蛋
 * @Date :2022/10/26 - 10 - 26 - 15:47
 */
public class User implements BeanNameAware , ApplicationContextAware , InitializingBean , DisposableBean {

    private int userId;

    private String userName;

    private String password;

    private String beanName;

    private ApplicationContext context;
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
        System.out.println("执行了对象属性的SET方法");
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User() {
        System.out.println("执行了对象的无参构造");
    }

    public void setBeanName(String s) {
        System.out.println("执行BeanNameAware 接口 ，注入bean名字:"+s);
    }
    public String getBeanName() {
        return beanName;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("执行ApplicationContextAware 接口， 注入容器");
    }
    public ApplicationContext getContext() {
        return context;
    }

    public void init(){
        this.userName = "shufen";
        System.out.println(" 执行了  自定义的 初始化方法"+userName);
    }
    public void afterPropertiesSet() throws Exception {
        this.userName = "cuihua";
        System.out.println("6 执行了 InitializingBean 接口的 afterPropertiesSet 初始化方法 "+userName);
    }

    public void Mydestroy() throws Exception {
        System.out.println("执行 自定义的销毁方法");
    }
    public void destroy() throws Exception {
        System.out.println("执行 DisposableBean 接口的销毁方法");
    }
    public void sayHi(){
        System.out.println("9 执行了 user自己的核心业务方法");
    }

}
